package com.xysq.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rockcent.model.CommentVModel;
import com.xysq.XYApplication;
import com.xysq.lemon.R;
import com.xysq.util.PropertiesUtil;

import java.util.List;

/**
 * Created by Steward_Han on 2015/10/8.
 */
public class EvaluateAdapterVOnePointOne extends BaseAdapter{

    private ViewHolder viewHolder;
    private Context context;
    private List<CommentVModel> commentVModelList;

    public EvaluateAdapterVOnePointOne(Context context, List<CommentVModel> commentVModels){
        this.context = context;
        this.commentVModelList = commentVModels;
    }

    @Override
    public int getCount() {
        return commentVModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return commentVModelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        viewHolder = new ViewHolder();
        if (null == convertView) {
            LayoutInflater mInflater = LayoutInflater.from(context);
            convertView = mInflater.inflate(R.layout.item_comment_item, null);
            viewHolder.headImg = (com.xysq.widget.CircleImageView) convertView.findViewById(R.id.img_sex);
            viewHolder.nameTxt = (TextView) convertView.findViewById(R.id.txt_name);
            viewHolder.commentTxt = (TextView) convertView.findViewById(R.id.txt_comment);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CommentVModel commentVModel = commentVModelList.get(position);
        viewHolder.nameTxt.setText(commentVModel.getName());
        viewHolder.commentTxt.setText(commentVModel.getComment());
        if(!TextUtils.isEmpty(commentVModel.getHeadUrl()) && !commentVModel.getHeadUrl().equals("null")) {
            XYApplication.getImageLoader().displayImage(PropertiesUtil.getImageServer() + commentVModel.getHeadUrl(), viewHolder.headImg);
        }else {
            viewHolder.headImg.setImageResource(R.drawable.def_img_head);
        }
        return convertView;
    }

    private class ViewHolder {
        com.xysq.widget.CircleImageView headImg;
        TextView nameTxt;
        TextView commentTxt;
    }
}
